#include<stdio.h>
int main()
{
int ch[5],i;
  for(i=0;i<5;i++)
  {
    scanf("%d",&ch[i]);
    if(ch[i]%27!=0)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}

